---
id: MqttServer
title: MqttServer
sidebar_label: 7.1、MqttServer
---

### （一）设备配置

| 属性           |  说明                    | 默认值/备注|
| ---------------| --------------------------| ---|
| 允许连接的Id(前缀)         | Mqtt客户端的连接Id需要加上此前缀，才能正常连接到网关的MqttServer  |ThingsGatewayId|
| IP         | 连接IP              | 127.0.0.1|
| 端口         | 连接端口              | 1883|
| 允许Rpc写入         | 是否允许写入变量              | True |
| Rpc写入Topic         | 客户端写入变量的发布Topic              | ThingsGateway/RpcWrite |
| Rpc返回Topic         | 客户端写入变量的订阅Topic，返回写入结果信息              | ThingsGateway/RpcSub |
| 变量Topic         | 变量信息订阅Topic              | ThingsGateway/Variable |
| 设备Topic         | 设备信息订阅Topic              | ThingsGateway/Device |

:::tip

 登录网关的MqttServer还需要配置第三方授权User，并且在客户端填写对应的UserName与Password


![](/img/mqttserver1.png)

:::

RpcJson：
```
{
  "Name":"tt8",//变量名称
  "Value":"12421",//变量值
  "RpcId":"testid"//当前RpcId
}
```
Rpc返回Json：
```
{
  "RpcId":"testid", //RpcId
  "Message":"操作成功",//返回消息
  "Success":true//是否成功
}
```

变量Json：
```

[
    {
        "deviceName": "ModbusTest",
        "rawValue": "12345",
        "value": "12345",
        "changeTime": "2023-03-08T08:42:36.1979048+08:00",
        "collectTime": "2023-03-08T08:46:39.3070467+08:00",
        "quality": 192,
        "readExpressions": null,
        "writeExpressions": null,
        "intervalTime": 1000,
        "otherMethod": null,
        "variableAddress": "40001",
        "name": "test40001",
        "description": null,
        "initialValue": null,
        "protectTypeEnum": 1,
        "dataTypeEnum": 7
    }
]
```
设备Json:
```
[
    {
        "pluginName": "ThingsGateway.Modbus.ModbusTcp",
        "deviceVariablesNum": 1,
        "activeTime": "2023-03-08T08:46:39.2708927+08:00",
        "deviceStatus": 1,
        "deviceOffMsg": "",
        "name": "ModbusTest",
        "description": null,
        "enable": true,
        "createTime": "2023-03-06T17:31:23.0562652",
        "updateTime": "0001-01-01T00:00:00"
    }
]

```



### （二）变量配置
无




